package com.labweb.conversor;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import com.labweb.entidades.Laboratorio;
import com.labweb.entidades.Software;
import com.labweb.servicos.LaboratorioService;
import com.labweb.servicos.SoftwareService;


public class LaboratorioConverter implements Converter{

	
	@Override
	public Object getAsObject(FacesContext context, 
	UIComponent component, String value) 
	throws ConverterException {
		if (value == null) {
			return null;
		}
		return new LaboratorioService()
		.pesquisarPorId(Integer.parseInt(value));
	}
	
	@Override
	public String getAsString(FacesContext context, 
	UIComponent component, Object object) 
	throws ConverterException {
			if (object == null) {
				return null;
			}
			Laboratorio laboratorio = (Laboratorio) object;
			return laboratorio.getNumero().toString();
	}

}
